﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using PlanningGIS.ManageUtility;

namespace PlanningGIS.Framework.Controls
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FrmTimer : Office2007Form
    {
        /// <summary>
        /// 
        /// </summary>
        public FrmTimer()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmTimer_Load(object sender, EventArgs e)
        {
            DateTime sysdate = ManageHelper.DBContext.GetSysDateTime();
            DateTime tmp = LockedTime.AddMinutes(ManageHelper.SecuritySet.LockTime);
            _target = tmp - sysdate;
            timer.Start();
        }

        /// <summary>
        /// 
        /// </summary>
        private string _msg="对不起，您的帐号<font color=\"#ED1C24\">已锁定</font>，请于<font color=\"#ED1C24\">{0}</font>之后再试！";

        /// <summary>
        /// 
        /// </summary>
        private TimeSpan _target;

        /// <summary>
        /// 
        /// </summary>
        public DateTime LockedTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Tick(object sender, EventArgs e)
        {
            if (_target.TotalSeconds > 0)
            {
                _target = _target - new TimeSpan(0, 0, 1);
                string s = String.Format("{0:mm}:{0:ss}", _target);
                //string s = String.Format("{0:hh}:{0:mm}:{0:ss}", _target);
                reflectionLabel.Text = string.Format(_msg, s);

            }
            else
            {
                timer.Stop();
                this.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
